package com.scuec.tourismwebsite.controller;

import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.FreeformPostComment;
import com.scuec.tourismwebsite.entity.PostComment;
import com.scuec.tourismwebsite.service.FreeformPostCommentService;
import com.scuec.tourismwebsite.vo.Fcomment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//
@RestController
@CrossOrigin
@RequestMapping("tour/v1")
public class FreeformPostCommentController {
    @Autowired
    private FreeformPostCommentService freeformPostCommentService;

    @GetMapping("Acomentpages")
    public PageInfo<Fcomment> findFcommentPages(@RequestParam Integer post_id,@RequestParam  Integer pageNum,@RequestParam Integer pageSize){
        return freeformPostCommentService.findFcommentPages(post_id, pageNum, pageSize);
    }

    @GetMapping("Acommentpage")
    public PageInfo<Fcomment> findFcommentPage(@RequestParam Integer post_id, @RequestParam String comment_content, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        return freeformPostCommentService.findFcommentPage(post_id, comment_content, pageNum, pageSize);
    }

    @DeleteMapping("Acomment/{comment_id}")
    public Integer deleteCommentById(@PathVariable Integer comment_id){
        return freeformPostCommentService.deleteCommentById(comment_id);
    }

    @GetMapping("Acomment")
    public List<Fcomment> findCommentById(@RequestParam Integer post_id){
        return freeformPostCommentService.findCommentrById(post_id);
    }

    @PostMapping("Acomment")
    Integer insertComment(@RequestBody FreeformPostComment freeformPostComment){
        return freeformPostCommentService.insertComment(freeformPostComment);
    }
}
